package com.sgb.kjwl.repository.impl;

import com.sgb.kjwl.model.api.ApiSource;
import com.sgb.kjwl.model.api.PreferenceSource;
import com.sgb.kjwl.model.entity.AddShoppingCar;
import com.sgb.kjwl.model.entity.DeleteShoppingCar;
import com.sgb.kjwl.model.entity.ShoppingCarEntity;
import com.sgb.kjwl.repository.ShoppingCarRepertory;
import com.swgk.core.base.api.BaseApiSource;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.preference.BasePreferenceSource;

import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import retrofit2.http.Body;

public class ShoppingCarRepertoryImpl extends BaseRepertoryImpl implements ShoppingCarRepertory {
    private ApiSource apiSource;
    private PreferenceSource preferenceSource;

    public ShoppingCarRepertoryImpl(BaseApiSource apiSource, BasePreferenceSource preferenceSource) {
        super(apiSource, preferenceSource);
        this.apiSource = (ApiSource) apiSource;
        this.preferenceSource = (PreferenceSource) preferenceSource;
    }

    @Override
    public Observable<BaseEntity<List<ShoppingCarEntity>>> getShoppingCarEntity(String id) {
        return apiSource.getShoppingCarEntity(id).compose(this.<BaseEntity<List<ShoppingCarEntity>>>rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity> addShoppingCar(AddShoppingCar addShoppingCar) {
        return apiSource.addShoppingCar(addShoppingCar).compose(this.<BaseEntity>rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<Boolean>> updateShoppingCar(@Body Map map) {
        return apiSource.updateShoppingCar(map).compose(this.<BaseEntity<Boolean>>rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity> deleteShoppingCar(DeleteShoppingCar deleteShoppingCar) {
        return apiSource.deleteShoppingCar(deleteShoppingCar).compose(this.<BaseEntity>rxSchedulerHelper());
    }
}
